experiment: PEP810 test compute lazy loading#17594
Closed
hebaalazzeh wants to merge 2 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for lazy-loading modules in Python 3.15+ by defining __lazy_modules__ in the package initialization templates and generated files. A critical issue was identified in the template where sys is used without being imported, which would lead to a NameError at runtime.
|
|
||
| from importlib import metadata | ||
|
|
||
| if sys.version_info >= (3, 15): |
Contributor
dabf6bd to
aedbee9
Compare
Contributor
Author
|
/gemini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is a proof-of-concept demonstrating the impact of native Python 3.15+ (PEP 810) lazy loading on a large generated GAPIC package (
google-cloud-compute).This PR applies the generator changes proposed in PR #17591 to the
google-cloud-computepackage. By utilizing the__lazy_modules__dictionary, the package defers importing underlying service modules until they are explicitly accessed, significantly reducing the initial import footprint and startup time.Note: This PR is currently for testing and review purposes to observe the generated diff and validate CI behavior. It depends on the generator changes in #17591
Changes Made
google-cloud-computeusing the updated gapic-generator templates.__lazy_modules__definition insidegoogle/cloud/compute_v1/__init__.pywrapped in anif sys.version_info >= (3, 15):block.ruff formatto ensure the generated dict aligns with CI formatting constraints.